//
// Created by Administrator on 2021/11/9.
//

#include "OrthoCameraHelper.h"

OrthoCameraHelper::OrthoCameraHelper(Vector3 location, Vector3 up, float left, float right, float bottom, float top,
                                     float nearplan, float farplan) {
    this->location = location;
    this->up = up;
    this->left = left;
    this->right = right;
    this->bottom = bottom;
    this->top = top;
    this->nearplan = nearplan;
    this->farplan = farplan;
}

void OrthoCameraHelper::onInit() {
    polygonMode = GL_LINE;
    drawMode = GL_LINES;

    //z方向相反
    farplan = nearplan + farplan;

    vertices = {
            location.x, location.y, location.z,//0
            left, bottom, nearplan,//1
            left, top, nearplan,//2
            right, bottom, nearplan,//3
            right, top, nearplan,//4

            // 为了颜色不一样，添加一组顶点
            left, bottom, nearplan,//5
            left, top, nearplan,//6
            right, bottom, nearplan,//7
            right, top, nearplan,//8

            left, bottom, farplan,//9
            left, top, farplan,//10
            right, bottom, farplan,//11
            right, top, farplan,//12

            (left + right) / 2, bottom, nearplan,//13
            (left + right) / 2, top, nearplan,//14
            left, (bottom + top) / 2, nearplan,//15
            right, (bottom + top) / 2, nearplan,//16

            (left + right) / 2, bottom, farplan,//17
            (left + right) / 2, top, farplan,//18
            left, (bottom + top) / 2, farplan,//19
            right, (bottom + top) / 2, farplan,//20
    };

    indices = {
            // 位置和near plan的连线
            0, 1, 0, 2, 0, 3, 0, 4,
            1, 2, 1, 3,
            2, 4, 3, 4,

            // 立方体框架
            // near plan
            5, 6, 5, 7,
            6, 8, 7, 8,

            // far plan
            9, 10, 9, 11,
            10, 12, 11, 12,

            // near - far的连接线
            5, 9, 6, 10,
            7, 11, 8, 12,

            // near 和 far plan 的中线的 +
            13, 14, 15, 16,
            17, 18, 19, 20,

            // 三角形

    };

    colors = {
            // 位置和near plan的连线
            1.0f, 0.0, 0.0f, 1.0f,
            1.0f, 0.0, 0.0f, 1.0f,
            1.0f, 0.0, 0.0f, 1.0f,
            1.0f, 0.0, 0.0f, 1.0f,
            1.0f, 0.0, 0.0f, 1.0f,
            // 立方体框架
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,
            1.0f, 1.0, 0.0f, 1.0f,

            //中线
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
            0.53f, 0.53f, 0.53f, 1.0f,
    };

    BufferGeometry::onInit();
}
